import csv
import os
# 读取文件sql_xxx.txt
files=['teacher','student', 'course','class','course_selection','department']
for f in files:
    with open(f'sql_{f}.txt', 'r') as file:
        #创建csv文件
        csv_file = open(f'csv_sql_{f}.csv', 'w', newline='')
        csv_writer = csv.writer(csv_file)
        sql_content = file.readlines()
        for line in sql_content:
            #每行形如(xxx,xxx,xxx,xxx),
            line=line[1:]
            line=line[:-3]
            items=line.split(',')
            csv_writer.writerow(items)
        csv_file.close()